﻿using System;
using System.Drawing;
using System.IO;
using System.Web;

namespace SAS.WebSite.Service
{
    /// <summary>
    /// Summary description for Base64ImageService
    /// </summary>
    public class Base64ImageService : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            var image = Image.FromStream(context.Request.Files[0].InputStream);
            MemoryStream ms = new MemoryStream();
            image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            string b64 = Convert.ToBase64String(ms.ToArray());
            context.Response.Write("data:image/png;base64," + b64);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}